package com.sduept.nwld.dataserver.manager.fault;

import com.sduept.core.dao.SuperDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * t_lbtz_signal_change表方法
 * @author Ningfw
 * @date 2017-07-03
 *
 */

@Service
public class SignalChangeManager {

	@Autowired
	private SuperDAO superDao;
	
	/**
	 * 根据fault_file_id查询信息
	 * @param faultFileId
	 * @return
	 */
	public List<?> findByFileId(String faultFileId){
		
		String sqlInfo = "SELECT s.fault_time,s.signal_name,s.signal_type,s.signal_flag,s.station_id,c.name,"
			+ "s.device_type,s.time_point,CASE WHEN b.name IS NOT NULL THEN b.name ELSE e.mProtectName END "
			+ "AS device_name FROM t_lbtz_signal_change s INNER JOIN t_cim_substation c ON s.station_id = c.id "
			+ "LEFT JOIN t_cim_breaker b ON s.device_id = b.id LEFT JOIN t_bx_protection_equipment e ON "
			+ "s.device_id = e.mRID WHERE s.fault_file_id = '"+faultFileId+"'";
		List<?> sigList = superDao.nativeQuery(sqlInfo);
		return sigList;
	}
	
	/**
	 * 查询一个站下的故障断路器、保护
	 * @param stationId
	 * @return
	 */
	public List<?> findByStationId(String stationId){
		String sqlInfo = "SELECT s.fault_time,s.signal_name,s.station_id,s.device_id,b.name,s.device_type,s.time_point "
			+ "FROM t_lbtz_signal_change s LEFT JOIN t_cim_breaker b ON s.device_id = b.id WHERE (s.device_type = 1 OR "
			+ "s.device_type = 2) AND s.station_id = '"+stationId+"'";
		List<?> signalList = superDao.nativeQuery(sqlInfo);
		return signalList;
	}
	
	/**
	 * 查询一个变电站下的保护动作时间
	 * @param stationId
	 * @return
	 */
	public List<?> findProtectByStation(String stationId){
		String sqlInfo = "SELECT sc.fault_time,pe.mProtectName,pe.mPrimdevID,sc.time_point,sc.device_id FROM t_lbtz_signal_change "
			+ "sc LEFT JOIN t_bx_protection_equipment pe ON sc.device_id = pe.mRID WHERE sc.device_type = 2 AND "
			+ "sc.station_id = '"+stationId+"'";
		List<?> signalList = superDao.nativeQuery(sqlInfo);
		return signalList;
	}
	
	
	/**
	 * 查询全部的断路器动作时间（保护响应时间分析模块）
	 * @return
	 */
	public List<?> findBreakerAll(){
		String sqlInfo = "SELECT sc.fault_time,sc.time_point,su.area1,cs.name,sc.signal_name FROM t_lbtz_signal_change sc LEFT JOIN "
			+ "t_cim_substation cs ON sc.station_id = cs.id LEFT JOIN t_imp_substation_coor2 su ON cs.name = su.name WHERE "
			+ "sc.device_type = 3";
		List<?> signalAllList = superDao.nativeQuery(sqlInfo);
		return signalAllList;
	}
	
}
